package py.com.fms.ven.persistence.services;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import com.ibatis.sqlmap.client.SqlMapClient;

import py.com.fms.exception.CommonException;
import py.com.fms.persistence.services.FmsServices;
import py.com.fms.ven.bean.ReceiptChargesHeadBean;
import py.com.fms.ven.bean.ReceiptChargesDetBean;

public class ReceiptChargesServices extends FmsServices  {

	public ReceiptChargesServices(SqlMapClient client) {
		super(client);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 [[[
	 [[ The following method retrieve a list of all records
	 [[ Normally used to load a grid.
	 */
	
	@SuppressWarnings("unchecked")
	public List<ReceiptChargesHeadBean> getAllReceiptChargesHead() throws CommonException{
		List<ReceiptChargesHeadBean> queryForList;
		try {
			
			//[[ queryForList is an implemented interface of iBatis ]]
			
			queryForList = (List<ReceiptChargesHeadBean>)this.getConfig().queryForList("receiptCharges.getAllReceiptChargesHead");
			return queryForList;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<ReceiptChargesDetBean> getAllReceiptChargesDet() throws CommonException{
		List<ReceiptChargesDetBean> queryForList;
		try {
			
			//[[ queryForList is an implemented interface of iBatis ]]
			
			queryForList = (List<ReceiptChargesDetBean>)this.getConfig().queryForList("receiptCharges.getAllReceiptChargesDet");
			return queryForList;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<ReceiptChargesDetBean> getReceiptChargesDetByHeadId(Long idHead) throws CommonException{
		List<ReceiptChargesDetBean> queryForList;
		
		HashMap<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("idHead", idHead);
		
		try {
			
			//[[ queryForList is an implemented interface of iBatis ]]
			
			queryForList = (List<ReceiptChargesDetBean>)this.getConfig().queryForList("receiptCharges.getReceiptChargesDetByHeadId", parameters);
			return queryForList;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	
	
	/**
	 [[[
	 [[ The following methods retrieve a Bean from a determinated Id
	 */
	
	
	public ReceiptChargesHeadBean getReceiptChargesHeadData(Long id) throws CommonException{
		ReceiptChargesHeadBean queryForObject;
		try {
			
			//[[ queryForList is an implemented interface of iBatis ]] 
			
			queryForObject = (ReceiptChargesHeadBean)this.getConfig().queryForObject("receiptCharges.getReceiptChargesHeadData", id);
			return queryForObject;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	
	public ReceiptChargesDetBean getReceiptChargesDetData(Long id) throws CommonException{
		ReceiptChargesDetBean queryForObject;
		try {
			
			//[[ queryForList is an implemented interface of iBatis ]] 
			
			queryForObject = (ReceiptChargesDetBean)this.getConfig().queryForObject("receiptCharges.getReceiptChargesDetData", id);
			return queryForObject;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	
	/**
	 [[[
	 [[ The following method store a bean (record) in the database.
	 */
	
	public void saveNewReceiptChargesHead(ReceiptChargesHeadBean receiptChargesHead) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().insert("receiptCharges.insReceiptChargesHead", receiptChargesHead);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	public void saveNewReceiptChargesDet(ReceiptChargesDetBean receiptChargesDet) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().insert("receiptCharges.insReceiptChargesDet", receiptChargesDet);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	/**
	 [[[
	 [[ The following method delete a record from the database.
	 */
	
	public void deleteReceiptChargesHeadById(Long id) throws CommonException{
		try {
			HashMap<String, Object> parameters = new HashMap<String, Object>();
			parameters.put("id", id);
			this.getConfig().startTransaction();
			this.getConfig().delete("receiptCharges.delReceiptChargesHeadById", parameters);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	public void deleteReceiptChargesDetById(Long id) throws CommonException{
		try {
			HashMap<String, Object> parameters = new HashMap<String, Object>();
			parameters.put("id", id);
			this.getConfig().startTransaction();
			this.getConfig().delete("receiptCharges.delReceiptChargesDetById", parameters);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	/**
	 [[[
	 [[ The following method update a record from a bean.
	 */
	public void updateReceiptChargesHeadById(ReceiptChargesHeadBean receiptChargesHead) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().update("receiptCharges.updReceiptChargesHeadById", receiptChargesHead);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	public void updateReceiptChargesDetById(ReceiptChargesDetBean receiptChargesDet) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().update("receiptCharges.updReceiptChargesDetById", receiptChargesDet);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	


}
